<?php

class Form_Registration extends Zend_Form
{

    public $buttonDecorators = array(
        'ViewHelper',
        array(array('data' => 'HtmlTag'), array('tag' => 'dd', 'class' => 'block')));

    public function init()
    {
        $this->setMethod(self::METHOD_POST);

        /* this Elements & Other Definitions Here ... */
        $first_name = $this->createElement('text', 'first_name');
        $first_name->setRequired(true);
        $first_name->addFilter('StringTrim');
        $first_name->setLabel('First name');
        $this->addElement($first_name);

        $last_name = $this->createElement('text', 'last_name');
        $last_name->setRequired(true);
        $last_name->addFilter('StringTrim');
        $last_name->setLabel('Last name');
        $this->addElement($last_name);

        //nutno dodelat validator emailove adresy a mozna zauvazovat o tom
        //jestli budeme chtit nejaky potvrzovaci email
        $email = $this->createElement('text', 'email');
        $email->setRequired(true);
        $email->addFilter('StringToLower');
        $email->addFilter("StringTrim");
        $email->addValidator(new Validate_EmailNotExists());
        $email->addValidator('EmailAddress');
        $email->setLabel('E-mail');
        $this->addElement($email);

        $lastfm = $this->createElement('text', 'last_fm_username');
        $lastfm->addValidator('stringLength', false, array(0, 20));
        $lastfm->setRequired(true);
        $lastfm->addFilter('StringTrim');
        $lastfm->addValidator(new LastFM_ValidateUser());
        $lastfm->addValidator(
                'Db_NoRecordExists', true,
                array('table' => 'user', 'field' => 'last_fm_username', 'messages' => array(
                        'recordFound' => 'Toto uživatelské jméno je již registrováno!'
                    )
                )
        );

        $lastfm->setLabel('Last.fm account');
        $this->addElement($lastfm);

        $password1 = $this->createElement('password', 'password1');

        $password1->setRequired(true);

        $password1->setLabel('Password');

        $password1->addValidator(new Zend_Validate_Alnum());
        $password1->addValidator(new Zend_Validate_StringLength(6));

        $password1->setAttrib('autocomplete', 'off');
        $this->addElement($password1);

        $password2 = $this->createElement('password', 'password2');
        $password2->setRequired(true);
        $password2->addValidator(new My_Validate_Password('password1'));
        $password2->setAttrib('autocomplete', 'off');
        $password2->setLabel('Retype password');
        $this->addElement($password2);

        $button = $this->createElement('button', 'Register_button', array("label" => "Register", "type" => "submit", "class" => "thoughtbot", "decorators" => $this->buttonDecorators));
        $this->addElement($button);
        /*
          $this->setElementDecorators(array(
          'ViewHelper',
          array(array('data' => 'HtmlTag'),  array('tag' =>'td', 'class'=> 'element')),
          array('Label', array('tag' => 'td')),
          array(array('row' => 'HtmlTag'), array('tag' => 'tr'))
          ));
          $this->setDecorators(array(
          'FormElements',
          array('HtmlTag', array('tag' => 'table')),

          'Form'
          ));
         *
         */
    }

}